<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">我的车源</view>
		</view>	
		<view class="search_maxbox" :class="scrrol == true ? 'scrrolHeader02' : ''">
			<view class="search_box">
				<view class="search">
					<view class="icon iconfont icon-sousuo"></view>
					<input type="text" v-model="keyword" value="" placeholder="输入关键词点击搜索" />
					<view class="menu" @click="search">搜索</view>
				</view>
			</view>
		</view>
		<view class="nav" :class="scrrol == true ? 'scrrolHeader02' : ''">
			<view class="navauto">
				<block v-for="(item, index) in menu" :key="index">
					<view class="menu" :data-index="index" @tap="setNavMenu">
						<view class="text" :class="index == select ? 'menucolor' : ''">{{ item.name }}
						   <view class="line" :class="index == select ? 'menucolor02' : ''"></view>
						</view>
					</view>
				</block>
			</view>
		</view>
		<view class="bg_box">
			<image class="bg01" :src="getImgSrc('/static/bg05.png')" mode="widthFix"></image>
			<view class="bg_content">
				<block v-for="(item, index) in list">
				<view class="car_box">
					<view class="btn03" v-if="item.status == 0">审核中</view>
					<view class="btn03" v-else-if="item.status == 1">上架</view>
					<view class="btn03" v-else >下架</view>
					<view class="car_list">
						<view class="car_img">
							<image :src="item.logo" mode="widthFix"></image>
						</view>
						<view class="car_text">
							<view class="title">{{item.title}}</view>
							<!-- <view class="text">{{item.configuration}}</view> -->
							<view class="text">{{item.year}}上牌 / {{item.mileage}}万公里 / {{item.city}}</view>
							<view class="card">
								<!-- <view class="t">闽</view> -->
								<!-- <view class="n">{{item.market_price}}万</view> -->
								<view class="nt">{{item.market_price}}万</view>
							</view>
						</view>
					</view>
					<view class="other_box">
						<!-- <view class="btn" v-if="item.status == 0">审核中</view>
						<view class="btn01" v-else-if="item.status == 1">上架</view>
						<view class="btn02" v-else >下架</view> -->
						<!-- <view class="other">
							<view class="i iconfont icon-changyonggoupiaorenshanchu"></view>
							<view class="t" @click="del_car(index)">删除</view>
						</view> -->
						<!-- <view class="other" :data-url="'/pages/service/publish01_edit?id='+item.id" @click="gotopage">
							<view class="i iconfont icon-bianji"></view>
							<view class="t">编辑</view>
						</view> -->
						<view class="other" >
							<view class="off_but" @click="update_car(index)" v-if="item.status == 1">刷新</view>
							<view class="off_but":data-url="'/pages/service/publish01_edit?id='+item.id" @click="gotopage">编辑</view>
							<view class="off_but" @click="off_car(index,2)" v-if="item.status == 1">下架</view>
							<view class="off_but" @click="off_car(index,1)" v-if="item.status == 2">上架</view>
							<!-- <view class="i iconfont icon-bianji"></view>
							<view class="t" @click="off_car(index,2)" v-if="item.status == 1">下架</view>
							<view class="t" @click="off_car(index,1)" v-if="item.status == 2">上架</view> -->
						</view>
					</view>
				</view>
				</block>
				<block v-if="empty_show">
					<view style="height: 10vh;padding-top: 6vw;text-align: center;">
						<u-empty text="没有更多了" mode="list">-- 没有更多了 --</u-empty>
					</view>
				</block>
				<view class="clear_box04"></view>
				

			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				scrrol:false,
				list:'',
				empty_show:0,
				select:0,
				status:0,
				menu: [
					{
						name: '全部'
					},
					{
						name: '上架'
					},
					{
						name: '下架'
					},
				],
				keyword:'',
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			setRule(e){
				let that = this;
				let index = e.currentTarget.dataset.index;
				that.flowList[index].tick = !that.flowList[index].tick
			},
			loadData() {
				let that = this;
				that.Net._get('auth/member/my_car_list', {page:that.page,status:that.status,keyword:that.keyword}, res => {
					if(res.code == 1){
						that.list = res.data;
						if (res.data == "") {
							that.empty_show = 1;
						}
					}
				});
			},
			del_car(idx){
				let that = this;
				uni.showModal({
				    title: '确认提示',
				    content: '是否确认删除',
				    success:(res) => {
				        if (res.cancel){
				            return false;
				        }
						uni.showLoading({
							title: '删除中'
						});
						let cid = that.list[idx].id;
						that.Net._post('auth/member/car_del_hand', {id:cid}, res => {
							if (res.code == 1) {
								that.Msg.Success('删除成功', res => {
									uni.hideLoading();
									that.list.splice(idx, 1);
								});
							}
						});
				    }
				});
			},
			off_car(idx,status){
				let that = this;
				let cid = that.list[idx].id;
				that.Net._post('auth/member/off_car', {id:cid,status,status}, res => {
					if (res.code == 1) {
						that.Msg.Success('操作成功', res => {
							if (that.select == 0 ){
								that.page == 1;
								that.loadData();
							}else{
								that.list.splice(idx, 1);
							}
						});
					}
				});
			},
			update_car(idx){
				let that = this;
				let cid = that.list[idx].id;
				that.Net._post('auth/member/car_update', {id:cid}, res => {
					if (res.code == 1) {
						that.Msg.Success('操作成功', res => {
							
						});
					}
				});
			},
			search(){
				/* if (this.keyword == '') {
					this.Msg.Fail('请输入搜索关键字');
					return '';
				} */
				this.page = 1;
				this.loadData();
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},
			setNavMenu(e) {
				let that = this;
				let index = e.currentTarget.dataset.index;
				that.select = index;
				that.status = index;
				that.page = 1;
				that.loadData();
			},
		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		onReachBottom() {
			var that = this;
			that.page++;
			that.Net._get('auth/member/my_car_list', {per_page:'10',page:that.page,}, res => {
				if (res.code == 1) {
					if (res.data == '') {
						uni.showToast({
							title: '没有更多了',
							duration: 2000,
							icon: 'none'
						});
						that.empty_show = 1;
					} else {
						that.list = that.list.concat(res.data); //将数据拼接在一起
					}
				} else if (res.code == 0) {
					that.Msg.Success(res.msg, res => {});
				}
			});
		},
	}
</script>

<style>
	
	/* .header{
		background-color: transparent !important;
		height: 18vw !important;
	}
	
	.header .text{
		background-color: transparent !important;
		color: #333 !important;
	} */
	
	.header .back{
		color: #fff !important;
	}
	.scrrolHeader{
		background-color: #FF7701 !important;
	}
	
	.scrrolHeader02{
		background-color: #fff !important;
	}
	.off_but{
		padding: 0 2vw 0 2vw;
		border-radius: 5vw;
		display: flex;
		align-items: center;
		border: 1px solid #333;
		margin-left: 1vw;
	}
	.bg_box{
		width: 100%;
		position: relative;
	}
	
	.bg_box .bg01{
		width: 100%;
	}
	
	.bg_box .bg_content{
		width: 92%;
		position: absolute;
		left: calc(50% - 46%);
		top: calc(38.5vw + var(--status-bar-height));
		z-index: 98;
	}
	
	.car_box{
		width: 100%;
		background-color: #fff;
		border-radius: 3vw;
		margin-top: 4%;
	}
	
	.car_list{
		display: flex;
		align-items: center;
		padding:2vw;
	}
	
	.car_list .car_text{
		flex: 1;
		margin-left: 1.5vw;
	}
	
	.car_list .car_text .title{
		font-size: 4.1vw;
		color: #333;
		font-weight: bold;
	}
	
	.car_list .car_text .text{
		font-size: 3.2vw;
		color: #666;
		margin-top: 2vw;
	}
	
	.car_list .car_text .card{
		margin-top: 2vw;
		display: flex;
		align-items: center;
		height: 6vw;
	}
	
	.car_list .car_text .card .t{
		width: 6vw;
		height: 100%;
		border-radius: 1vw 0 0 1vw;
		background-color: #FC5E21;
		font-size: 3.2vw;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.car_list .car_text .card .n{
		height: 100%;
		border-radius: 0 1vw 1vw 0;
		background-color: #FFF7F4;
		font-size: 3.2vw;
		padding: 0 2vw;
		color: #FC5E21;
		display: flex;
		align-items: center;
	}
	
	.car_list .car_img{
		width: 35vw;
		/* margin-left: -4vw; */
	}
	
	.car_img image{
		border-radius: 3vw;
	}
	
	.other_box{
		width: 100%;
		height: 10vw;
		display: flex;
		/* border-top: 1px solid #F3F3F3; */
	}
	
	.other_box .other{
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	
	.other_box .other:nth-child(1){
		border-right: 1px solid #F3F3F3;
	}
	
	.other_box .other .i{
		font-size: 5vw;
		color: #B8B8B8;
		margin-right: 1vw;
	}
	
	.other_box .other .t{
		font-size: 3.8vw;
		color: #666666;
	}
	
	.btn{
		background-color: #FFEDDF;
		color: #FB7D10;
		height: 7vw;
		line-height: 7vw;
		text-align: center;
		font-size: 3.2vw;
		border-radius: 2vw;
		padding: 0vw 2vw;
		margin: 3vw;
	}
	.btn01{
		background-color: #E8F0FF;
		color: #1B66FF;
		height: 7vw;
		line-height: 7vw;
		text-align: center;
		font-size: 3.2vw;
		border-radius: 2vw;
		padding: 0vw 2vw;
		margin: 3vw;
	}
	.btn02{
		background-color: #FFE4E1;
		color: #FD4C38;
		height: 7vw;
		line-height: 7vw;
		text-align: center;
		font-size: 3.2vw;
		border-radius: 2vw;
		padding: 0vw 2vw;
		margin: 3vw;
	}
	
	.nav {
		width: 100%;
		height: 13.5vw;
		overflow: hidden;
		overflow-x: auto;
		position: fixed;
		left: 0;
		top: calc(25.4vw + var(--status-bar-height));
		z-index: 99;
		background-color: #fff;
			border-bottom: 1px solid #e8e8e8;
		box-sizing: border-box;
	}
	
	.nav .navauto {
		width: fit-content;
		display: flex;
		justify-content:space-around;
		/* margin-left: 4%; */
		min-width: 100%;
	}
	
	.nav .navauto .menu {
		/* width: 20%; */
		
	}
	
	.nav .navauto .menu .text {
		font-size: 4.5vw;
		color: #666666;
		text-align: center;
		line-height: 13.5vw;
		position: relative;
	}
	
	.nav .navauto .menu .line {
		width: 100%;
		height: 2.3vw;
		background-color: #FF7701;
		border-radius: 2.3vw;
		position: absolute;
		left: calc(50% - 50%);
		bottom: 3.5vw;
		z-index: -1;
		display: none;
		
	}
	
	.menucolor {
		color: #091624 !important;
		font-weight: bold;
		font-size: 4.7vw !important;
	}
	
	.menucolor02 {
		display: block !important;
	}
	
	.menucolor03 {
		background-color: #FF9822 !important;
	}
	.clear_box02{
		height: 13.5vw !important;
	}
	.search_maxbox {
		width: 100%;
		padding: 3vw 4%;
		position: fixed;
		left: 0;
		top: calc(13vw + var(--status-bar-height));
		z-index: 999;
		background: #fff;
	}
	
	.search_box {
		width: 100%;
		border-radius: 2vw;
		border: 1px solid #FC5D20;
		display: flex;
		align-items: center;
		height: 11vw;
		padding-left: 2vw;
	}
	
	.search_box .city_box {
		display: flex;
		align-items: center;
		padding: 0 2vw;
		border-right: 1px solid #E8E8F0;
		margin-right: 2vw;
	}
	
	.search_box .city_box .city {
		font-size: 3.8vw;
		color: #979AA9;
		margin-right: 1vw;
	}
	
	.search_box .city_box .arrow {
		font-size: 3vw;
		color: #979AA9;
	}
	
	.search_box .search {
		flex: 1;
		display: flex;
		align-items: center;
	}
	
	.search_box .search .icon {
		font-size: 4vw;
		color: #979AA9;
		margin-right: 2vw;
	}
	
	.search_box .search input {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
	}
	
	.search_box .search .menu {
		font-size: 4vw;
		height: 9vw;
		width: 16vw;
		color: ##F44336;
		/* background-color: #FE811E; */
		border-radius: 2vw;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 1.5vw;
	}
	
	.btn03 {
	    height: 7vw;
	    line-height: 7vw;
	    text-align: end;
	    font-size: 3.2vw;
	    padding: 0vw 2.5vw;
	}
	
	.nt{
		color: #FD4C38;
		font-size: 5vw;
	}
</style>
